package cn.stimd.spring.validation;

import cn.stimd.spring.beans.BeanWrapper;
import cn.stimd.spring.beans.BeanWrapperImpl;
import cn.stimd.spring.beans.ConfigurablePropertyAccessor;

import java.io.Serializable;

/**
 * Errors和BindingResult的默认实现
 * <p>
 * Created by Stimd
 * 项目地址：https://gitee.com/stimd/spring-wheel
 * 公众号：Java编程探微
 */
public class BeanPropertyBindingResult extends AbstractPropertyBindingResult implements Serializable {
    private final Object target;
    private transient BeanWrapper beanWrapper;

    public BeanPropertyBindingResult(Object target, String objectName) {
        super(objectName);
        this.target = target;
        this.beanWrapper = new BeanWrapperImpl(target);
    }


    @Override
    public Object getTarget() {
        return this.target;
    }


    @Override
    public ConfigurablePropertyAccessor getPropertyAccessor() {
        return this.beanWrapper;
    }
}
